/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BrushFrame.java
 *
 * Created on Nov 4, 2011, 7:42:36 AM
 */
package teletutor.blackboard.expansion.toolpack;

import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import teletutor.core.utilities.FrameUtil;

/**
 *
 * @author msi
 */
public class BrushFrame extends javax.swing.JFrame {

    BrushTool bTool = null;
    ImageIcon paletteIcon = new ImageIcon(getClass().getResource("/palette.jpg"));
    BufferedImage paletteImage = new BufferedImage(60, 200, BufferedImage.TYPE_3BYTE_BGR);

    /** Creates new form BrushFrame */
    public BrushFrame(BrushTool bTool) {
        initComponents();
        this.bTool = bTool;
        paletteImage.getGraphics().drawImage(paletteIcon.getImage(), 0, 0, null); 
        
        FrameUtil.centerFrameOnScreen(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        colorPicker = new javax.swing.JLabel();
        size1 = new javax.swing.JButton();
        size2 = new javax.swing.JButton();
        size3 = new javax.swing.JButton();
        size4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setAlwaysOnTop(true);
        setResizable(false);

        colorPicker.setIcon(new javax.swing.ImageIcon(getClass().getResource("/palette.jpg"))); // NOI18N
        colorPicker.setText("colorPicker");
        colorPicker.setMaximumSize(new java.awt.Dimension(60, 200));
        colorPicker.setMinimumSize(new java.awt.Dimension(60, 200));
        colorPicker.setPreferredSize(new java.awt.Dimension(60, 200));
        colorPicker.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                colorPickerMouseClicked(evt);
            }
        });

        size1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/size1.jpg"))); // NOI18N
        size1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        size1.setMaximumSize(null);
        size1.setMinimumSize(null);
        size1.setName(""); // NOI18N
        size1.setPreferredSize(null);
        size1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                size1ActionPerformed(evt);
            }
        });

        size2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/size2.jpg"))); // NOI18N
        size2.setBorderPainted(false);
        size2.setMaximumSize(null);
        size2.setMinimumSize(null);
        size2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                size2ActionPerformed(evt);
            }
        });

        size3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/size3.jpg"))); // NOI18N
        size3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                size3ActionPerformed(evt);
            }
        });

        size4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/size4.jpg"))); // NOI18N
        size4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                size4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(size1, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                    .addComponent(size2, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                    .addComponent(size3, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                    .addComponent(size4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(colorPicker, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(size1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(size2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(size3)
                        .addGap(18, 18, 18)
                        .addComponent(size4))
                    .addComponent(colorPicker, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void size3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_size3ActionPerformed
        bTool.setBrushWidth(15);
    }//GEN-LAST:event_size3ActionPerformed

    private void size1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_size1ActionPerformed
       bTool.setBrushWidth(2);
    }//GEN-LAST:event_size1ActionPerformed

    private void colorPickerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_colorPickerMouseClicked
        bTool.setColor(new Color(paletteImage.getRGB(evt.getX(), evt.getY()))); 
    }//GEN-LAST:event_colorPickerMouseClicked

    private void size2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_size2ActionPerformed
        bTool.setBrushWidth(6);
    }//GEN-LAST:event_size2ActionPerformed

    
    private void size4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_size4ActionPerformed
       bTool.setBrushWidth(40);
    }//GEN-LAST:event_size4ActionPerformed

    /**
     * @param args the command line arguments
     */
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel colorPicker;
    private javax.swing.JButton size1;
    private javax.swing.JButton size2;
    private javax.swing.JButton size3;
    private javax.swing.JButton size4;
    // End of variables declaration//GEN-END:variables
}
